package com.qr.config;

import com.qr.properties.AliOssProperties;
import com.qr.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 1、先创建阿里云对象
 */
@Configuration
@Slf4j
public class OssConfig {

    // 2、读取配置文件，创建阿里云对象
    @Bean
    @ConditionalOnMissingBean //没有这个bean的时候再去创建
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("创建阿里云对象" + aliOssProperties);
        return new AliOssUtil(
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
